/**
 *	菜单管理menu流程模块接口
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-19
 */

package com.framework.Module.system.menu;


import com.framerock.baselib.Json;
import com.framerock.baselib.Rock;
import com.framework.Flow.Flow;
import com.framework.Flow.FlowListener;
import com.framework.Model.ModelMode;

import java.util.Map;


public class FlowListenermenu extends FlowListener {



    @Override
    public Boolean onModejs() {
        return true;
    }

    public Map<String, String> onSavebefore(Map<String, String> da, String mid, Boolean isadd)
    {
        Map<String, String> map = Rock.getMap();
        String pid = Rock.getMapString(da, "pid");
        String msg = "";
        if(!pid.equals("0")){
            if(pid.equals(mid)) {
                msg = "上级ID不能写" + pid + "";
                return mFlow.setErrors(msg);
            }else{
                int to = mFlow.mModel.getCount(pid);
                if(to==0){
                    msg = "上级ID("+pid+")不存在";
                    return mFlow.setErrors(msg);
                }
            }
        }
        map.put("msg", msg);
        return map;
    }

    public Map<String, String> onDatabefore(){
        String pid    = mRequest.get("pid", "0");
        String where  = "(`pid`="+pid+" or `id`="+pid+")";
        return Rock.getMap(new String[]{
                "where", where,
        });
    }

    public Map<String, String> onDataafter()
    {
        int loadci  = Integer.parseInt(mRequest.get("loadci", "1"));
        Map<String, String> da = Rock.getMap();
        if(loadci == 1){
            da.put("menuarr", Json.getListString(mFlow.mModel.getAll("1=1", "`id`,`name`,`pid`", "`sort`")));
        }
        return da;
    }
}
